﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using KSUNO_EMS.Models;

namespace KSUNO_EMS.Controllers
{
    public class EmsController : Controller
    {
        protected EmsDb Database = new EmsDb();

        protected override void Dispose(bool disposing)
        {
            Database.Dispose();
            base.Dispose(disposing);
        }

        public RedirectToRouteResult VerifyAccess(string accessLevel)
        {
            var user = MvcApplication.GetCurrentUserInfo();
            if (user == null)
            {
                FormsAuthentication.SignOut();
                return RedirectToAction("Index", "Login");
            }
            else if (accessLevel == "Manager" && user.Role != "Manager")
                return RedirectToAction("Unauthorized", "Login");

            return null;

        }
    }
}
